package com.ldodds.ot.property;

import java.util.Map;

/**
 * Default implementation of the PropertyMapper interface that maintains a 
 * Map of mappings from URIs to labels. The keys in this map may be full 
 * predicate URIs or namespace URIs. 
 * 
 * <p>
 * This provides support for providing explicit mappings for specific predicates, 
 * or mapping a set of predicates based on their common namespace URI. In the 
 * latter case, the value associated with the namespace URI will be a prefix that 
 * is concatenated with the property name. E.g. if <code>http://xmlns.com/foaf/0.1</code> 
 * were mapped to <code>foaf</code>, then the <code>http://xmlns.com/foaf/0.1</code> property will 
 * be mapped to <code>foaf_name</code>. 
 * </p>
 * <p>
 * The separator used in the concatenation defaults to an underscore character but can 
 * be altered by using the alternate constructor.
 * </p>
 * 
 * @author Leigh Dodds
 */
public class PropertyMapperImpl extends AbstractPropertyMapper
{
	private Map<String,String> mappings;
	private String separator;
	
	public PropertyMapperImpl(Map<String,String> mappings) {
		this(mappings, DEFAULT_SEPARATOR);
	}

	public PropertyMapperImpl(Map<String,String> mappings, String separator) {
		this.mappings = mappings;
		this.separator = separator;
	}
		
	@Override
	protected String mapURI(String propertyURI) {
		return mappings == null ? null : mappings.get(propertyURI);
	}

	@Override
	protected String mapBaseURI(String baseURI) {
		return mappings == null ? null : mappings.get(baseURI);
	}

	protected String getSeparator() {
		return separator;
	}
}
